package emulator;

import java.util.HashSet;

import keyboard.GroupCostCalculatorUsingFingertip;
import keyboard.Keyboard;
import keyboard.Position;

public class ResultCostCalculatorGroupSize extends ResultCostCalculator {
	/*float[][] sizeCost = {
			{},
			{0f, 1.732275f, 0.874231f, 0.841463f, 0.905258f, 0.811453f, 0.797088f, 0.786931f, 0.802444f, 0.850775f, 0.805220f},
			{0f, 1.181598f, 0.670635f, 0.621711f, 0.602394f, 0.571606f, 0.540294f, 0.521975f, 0.531081f, 0.526450f, 0.519300f},
			{0f, 1.102231f, 0.566475f, 0.550513f, 0.547481f, 0.577294f, 0.544981f, 0.521525f, 0.501377f, 0.505244f, 0.530053f}
	};*/
	
	public ResultCostCalculatorGroupSize(String strategy, int dictSize) {
		super(strategy, dictSize);
		this.costType = "groupSize";
	}

	@Override
	public float CalnCost(Keyboard keyboard, Result result) {
		String word = result.GetWord();
		float cost = 0f;
		
		for (int i = 0; i < word.length(); i++) {
			keyboard.GroupingStaticKeyboard(result.GetExpression(i));
			HashSet<Character> keysGroup = keyboard.GetKeysGroupOfLetter(word.charAt(i));
			Position size = keyboard.GetGroupSize(keysGroup);
			//cost += sizeCost[(int)size.r][(int)size.c];
			cost += GroupCostCalculatorUsingFingertip.calnCostBySize(size);
		}
		
		Position nextSize = keyboard.GetNextSize();
		Position selectorSize = keyboard.GetSelectorSize();
		//cost += sizeCost[(int)selectorSize.r][(int)selectorSize.c];
		//cost += sizeCost[(int)nextSize.r][(int)nextSize.c] * ((result.GetPriority() - 1) / 4);
		cost += calnCostBySize(selectorSize);
		cost += calnCostBySize(nextSize) * ((result.GetPriority() - 1) / 4);
		return cost;
	}
	
	private float calnCostBySize(Position size) {
		return GroupCostCalculatorUsingFingertip.calnCostBySize(size);
	}
}
